package com.liuhuanss.idCard.controller;

import com.liuhuanss.idCard.pojo.dto.IdCardRecognitionResponse;
import com.liuhuanss.idCard.pojo.dto.ResponseData;
import com.liuhuanss.idCard.service.IdCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/idcard")
public class IdCardController {


    @Autowired
    private IdCardService idCardService;

    @PostMapping("/recognize")
    public ResponseEntity<?> recognizeIdCard(@RequestParam("file") MultipartFile file) {
        try {
            ResponseData response = idCardService.recognizeIdCard(file);
            return ResponseEntity.ok(response);
        } catch (Exception e) {
            return ResponseEntity.internalServerError().body("识别失败: " + e.getMessage());
        }
    }
}
